package com.caojin.propertyInjector.locationResolver;

import java.io.InputStream;

public abstract class LocationResolver {
	// classpath形式的url路径前缀
	public static final String CLASSPATH_PREFIX = "classpath:";
	// 文件系统形式的url路径前缀
	public static final String FILESYS_PREFIX = "file:";
	// 默认的配置文件名
	public static final String DEFAULT_FILE_NAME = "props.properties";
	// 路径前缀
	protected String pathPrefix;

	public LocationResolver(String pathPrefix) {
		this.pathPrefix = pathPrefix;
	}

	/**
	 * 获取文件的url(带路径前缀)
	 * 
	 * @return
	 */
	public String getFileUrl() {
		return pathPrefix + getBaseUrl();
	}

	/**
	 * 获取文件的URL
	 * 
	 * @return
	 */
	protected abstract String getBaseUrl();

	/**
	 * 获取文件流
	 * 
	 * @return
	 */
	public abstract InputStream getInputStream();

	@SuppressWarnings("serial")
	class UnlocatedException extends RuntimeException {
		public UnlocatedException(String msg) {
			super(msg);
		}
	}
}
